package com.learn.controller;

import com.learn.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Arrays;

/**
 * @author DJJ_F
 * @version 1.0
 * @date 2025/01/24
 * @description
 */
@Controller
public class UserController {
    @RequestMapping("/")
    public String registerPage() {
        return "register";
    }

    @RequestMapping("/register")
    public String register(
            @RequestParam String username,
            @RequestParam("password") String password,
            @RequestParam(value = "gender", required = false, defaultValue = "30") Integer gender,
            @RequestParam("hobbies") String[] hobbies,
            @RequestParam("intro") String intro
    ) {
        System.out.println(gender);
        System.out.println(Arrays.toString(hobbies));
        return "ok";
    }

    @RequestMapping("/register2")
    public String register2(String username,
                            String password,
                            Integer gender,
                            String hobbies,
                            String intro) {
        //[sing, dance] 复选框等多项的内容也可以用string接收
        System.out.println(hobbies);
        return "ok";
    }

    @RequestMapping("/register3")
    public String register3(
            User user,
            @RequestHeader(value = "host", required = false, defaultValue = "")
            String host,
            @CookieValue(value = "id", required = false, defaultValue = "")
            String cookie
            ) {
        System.out.println(user);
        System.out.println(host);
        System.out.println(cookie);
        return "ok";
    }
}
